from PySide2.QtWidgets import QMainWindow,QWidget,QMessageBox
from PySide2.QtCore import Qt,QTimerEvent
from PySide2.QtGui import QCloseEvent
from widget.ui_main import Ui_MainWindow

from widget.mainCentralWidget import MainCentralWidget


class AutoClickMainWindow(QMainWindow):

    def __init__(self, parent: QWidget = None, flags: Qt.WindowFlags = Qt.WindowFlags()) -> None:
        super().__init__(parent, flags)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.central_widget = MainCentralWidget(self)
        self.central_widget.SigMessage.connect(self.update_status_text)
        self.central_widget.SigFindPosi.connect(self.window_min)
        self.setCentralWidget(self.central_widget)
        self.resize(1600, 1000)
        self.ui.action_abort.triggered.connect(self.abort)
    
    def closeEvent(self, event: QCloseEvent) -> None:
        self.central_widget.close_clear()
        event.accept()

    def window_min(self, yes:bool):

        if yes:
            self.setWindowState(Qt.WindowState.WindowMinimized)
        else:
            self.setWindowState(Qt.WindowState.WindowNoState)

    def update_status_text(self, text:str):

        self.statusBar().showMessage(text, 1500)
        self.ui.textBrowser.append(text)

    def abort(self) -> None:

        QMessageBox.about(self, '关于', '52破解，仅限于学习使用!')